import { VueComponent, Prop } from 'vue-typescript'
import { azureBlob } from '../../service/azure-blob-upload'
import {dataService} from '../../service/dataService';
import * as VueRouter from 'vue-router'

var VueTables = require('vue-tables');
Vue.use(VueTables.client,{
    filterable:false,
    compileTemplates:true,
    pagination: {
     dropdown:false,
    },
    texts:{
     count:'{count} 条',
    }
    
});
var router = new VueRouter();
@VueComponent({
    template: require('./inquiryCheck.html'),
    // style: require('./home.scss')
})
export class InquiryCheckComponent extends Vue {
    el:'#inquiryCheckEl'
    components:({
        vclienttable:any,
    })
   
  
    sortable=[];
    deleteMe=function(id){
        //调后台接口(删除)
        // console.info('test');
        
    }
    package:string = 'vue-typescript';
    repo:string = 'https://github.com/itsFrank/vue-typescript';

    // // 下拉选择框 select onChange
    // goodsTypeSelect(event, item) {
    //     item.drug_id = parseInt(event.target.value) 
    // }
    //v-model初始化
    id=""
    // @Prop
    


    quotation:boolean=false;
    inquiryChildId="";//子询价单编号
    responseTime:string='';//紧急程度
    responseTimeUnit="";//紧急程度单位
    creationTime=""//下单那时间
    clientName=""//客户单位
    customerName=""//发货计划人
    customerPhone=""//发货人电话
    content=""//总询价内容
    originProvinceStr="";
    originCityStr="";
    originCountyStr="";
    originDetails="";
    destinationProvinceStr="";
    destinationCityStr="";
    destinationCountyStr="";
    destinationDetails="";
    foreArrivalTime="";
    foreDeliveryTime="";

    goodsName="";
    goodsTypeName="";
    goodsTypeId="";
    goodsId="";

    quantityOfGoods="";
    goodsUnit="";
    //车辆信息
    vehicleTypeStr="";
    carLengthStr="";
    carriageWayStr="";
    loadingEffect=""//装车效果

    consignor:string='';
    consignorPhone:string='';
    starProvince:string='';
    starCity:string='';
    starAreaCity:string='';
    startAddress:string='';
    endProvince:string='';
    endCity:string='';
    endArea:string='';
    endAddress:string='';
    plannedArrivalTime:string="";
    plannedDeliveryTime:string=''
    goodsQuantity:string=''
    goodsQuantityUnit:string=''
    carType:string=''
    
    carrierCategory:string=''
    
    attachmentDetails:string=''
    quotationAmount:string=''
    quotationAmountUnit:string=''
    quotationDescription:string=''

    remarks="";
    receivablePrice="";
    receivablePriceUnitStr="";
    receivableSummary=""

    // quotationAmount=""//报价金额
    // quotationAmountUnit=""//报价单位
    // quotationDescription=""//报价说明


    winBid=true;
    loseBid=true;
    uk=true;


    //设置禁用（详情）
    status:string="";
    titleInquiry:string=''
    //sasUrl
    @Prop
    goodsQuantityUnitDropDown=[{"text": "吨","value": "1"},{"text": "立方","value": "2"},{ "text": "车","value": "3"},{"text": "件","value": "4"},{"text": "托","value": "5"},{"text": "台","value": "6"},{"text": "其他","value": "7"}]
    carTypeDropDown=[{"text": "厢车","value": "1"},{"text": "飞翼","value": "2"},{"text": "半挂","value": "3"},{"text": "标厢","value": "4"}, {"text": "大平板","value": "5"},{"text": "平板","value": "6"},{"text": "高低板","value": "7"},{"text": "高栏平板","value": "8"},{"text": "高栏高低板", "value": "9"},{"text": "大件车抽拉板", "value": "10"},{ "text": "大件车超低板", "value": "11"},{"text": "自卸车","value": "12"},{"text": "单车","value": "13"},{"text": "其他", "value": "14" }]
    carLengthDropDown=[{ "text": "4.2米","value": "1"},{"text": "5.8米","value": "2"}, {"text": "6米","value": "3"}, { "text": "6.2米","value": "4" }, { "text": "6.5米", "value": "5"},  {"text": "6.8米","value": "6" }, {"text": "7.6米","value": "7"},{"text": "8.6米","value": "8"},{ "text": "8.7米","value": "9"},{"text": "9.6米","value": "10"},{ "text": "13米", "value": "11"},{"text": "13.5米","value": "12" },{"text": "16米","value": "13"},{"text": "17.5米","value": "14" }, {"text": "其他","value": "15"}]
    carrierCategoryDropDown=[{"text": "整车","value": "1"},{"text": "零担", "value": "2" }, {"text": "整车/零担","value": "3"}] 
    urgencyUnitDropDown=[{text:"天",value:"1"},{text:"时",value:"2"},{text:"分",value:"3"}];
    // starProvinceList=[{text:"北京",value:"01"},{text:"南京",value:"02"}];
    quotationAmountUnitDropDown=[{"text": "元/车","value": "1"},{"text": "元/吨","value": "2"},{"text": "元/立方","value": "3"},{"text": "元/件","value": "4"},
                                {"text": "元/公里","value": "5"},{"text": "元/工程","value": "6"},{"text": "元/吨*公里","value": "7"},{"text": "元/托","value": "8"},
                                {"text": "","value": "9"}];
      statusList=[
        {text:"全部",value:""},
        {text:"报价中",value:"2,3,4,5,6,7"},//
        {text:"已报价",value:"8"},
        {text:"已中标",value:"9"},//
        {text:"未中标",value:"10"},//
        {text:"中标待定",value:"11"},
        {text:"询价终结",value:"12"},//
    ]
   
    goodsTypeDropDown=[];
    goodsNameDropDown=[];

    
    originProvinceList=[];
    originCityList=[];
    originCountyList=[];
    destinationProvinceList=[];
    destinationCityList=[];
    destinationCountyList=[];

    sasUrl:string='https://sinostoragedev.blob.core.chinacloudapi.cn/avatar-container?sv=2016-05-31&sr=c&sig=nUNfvCUrZ%2F%2Bjuc%2Fesjjl0tXw7nY4E4JJJ8jD7PBSUjI%3D&st=2017-01-26T06%3A19%3A15Z&se=2017-01-27T06%3A24%3A15Z&sp=racwl';
    imageLists=[];
    object:{default:string} = {default: 'Default object property!'}; //objects as default values don't need to be wrapped into functions
    imageColumns =['name','rate','state','operation'];
    imageOptions= {
        headings:{
            // image:'图片',
            name:"名称",
            // size:"大小",
            rate:"进度",
            state:"状态",
            operation:'操作'
        },
        templates: {
            operation: function(row) {
               
                return `<button  type="button" class="btn btn-primary btn-xs btnDownLoad" @click="$parent.download(${row.index})">
                        <span class="fa fa-cloud-download"></span> 下载
                    </button>`
            },
             state:function(row){
                return `<span class='glyphicon glyphicon-ok text-success' id="${row.id}" title='状态显示'></span>`;
            },
            rate:function(row){
                return `<div class="progress" style="width:60%"><div class="progress-bar progress-bar-uploadFile" id='${row.id}progressBar' role="progressbar" style="width:100%"></div></div>`;
            }
            /**
             * 这里图片也不用显示出来，只显示图片名
             */
            // image:function(row){
            //     return `<div class="img-thumbnail" style="position:relative">
            //                 <img class="img-responsive"  src="${row.path}" style="width:236px;height:298px" />
            //             </div>`
            // }
        },
    };
  
    //uploade img
    download=function(index){
       
        // 这里下载先搁置，等后台接口
        // var url=this.imageLists.filter(t=>t.index==index)[0].path;
        
        // window.location.href = url;
        //  // Get file name from url.
        // var filename = url.substring(url.lastIndexOf("/") + 1).split("?")[0];
        // var xhr = new XMLHttpRequest();
        // xhr.responseType = 'blob';
        // xhr.onload = function () {
        //     var a = document.createElement('a');
        //     a.href = window.URL.createObjectURL(xhr.response); // xhr.response is a blob
        //     a.setAttribute('download',filename)
        //     a.style.display = 'none';
        //     document.body.appendChild(a);
        //     a.click();
        //     a=null;
        // };
        // xhr.open('GET', url);
        // xhr.send();

        //调用接口下载附件
        var id=this.imageLists.filter(t=>t.index==index)[0].id;
        window.location.href = dataService().baseUrl+ "Attachment/getAttachment/"+ id;
        
    }
   
    //uploader image
    ready(){
        

        // $('#realHead').bind('change', 'RealHead', this.handleFileSelect);
        this.id=this.$route.query.id;
        

        
        
       
       
        //判断订单状态
        
        

        dataService().Inquiry.getInquiry(this.id).then((res)=>{
            // console.log("res in 询价详情",res)
            this.status=res.states;
            this.status=this.statusList.filter(t=>t.value.indexOf(this.status)>-1)[0].text;
            switch(this.status){
                case '已报价':{
                    this.titleInquiry='询价单审核详情';
                    this.quotation=true;
                    this.winBid=true;
                    this.loseBid=true;
                    this.uk=true;
                };break;
                case '中标待定':{
                    this.titleInquiry='询价单审核详情';
                    this.quotation=true;
                    this.winBid=true;
                    this.loseBid=true;
                    this.uk=false;
                };break;
                    case '未中标':;
                case '已中标':{
                    this.titleInquiry='询价单详情';
                    this.quotation=true;
                    this.winBid=false;
                    this.loseBid=false;
                    this.uk=false;
                };break;
                case '询价终结':;
                case '报价中'||'询价终结':{
                    this.titleInquiry='询价单详情';
                    this.quotation=false;
                    this.winBid=false;
                    this.loseBid=false;
                    this.uk=false;
                };break;
                default:{
                    this.titleInquiry='询价单审核详情';
                    this.quotation=true;
                    this.winBid=true;
                    this.loseBid=true;
                    this.uk=true;
                }
            }
            // console.log("res in inquiry check",res);
            //总询价内容
            this.inquiryChildId=res.inquiryChildId;
            this.responseTime=res.responseTime;
            this.responseTimeUnit=res.responseTimeUnit;
            this.creationTime=res.creationTime;
            this.clientName=res.clientName;
            this.customerName=res.customerName
            this.customerPhone=res.customerPhone
            
            this.content=res.content

            //线路信息
            this.originProvinceStr=res.originProvinceStr
            this.originCityStr=res.originCityStr
            this.originCountyStr=res.originCountyStr
            this.originDetails=res.originDetails
            

            this.destinationProvinceStr=res.destinationProvinceStr
            this.destinationCityStr=res.destinationCityStr
            this.destinationCountyStr=res.destinationCountyStr
            this.destinationDetails=res.destinationDetails

            this.foreArrivalTime=res.foreArrivalTime
            this.foreDeliveryTime=res.foreDeliveryTime

            this.goodsName=res.goodsName
            this.goodsTypeName=res.goodsTypeName
            this.goodsTypeId=res.goodsTypeId
            this.goodsId=res.goodsId

            

            this.quantityOfGoods=res.quantityOfGoods
            this.goodsUnit=res.goodsUnit
            //所需车辆信息
            this.vehicleTypeStr=res.vehicleTypeStr
            this.carLengthStr=res.carLengthStr
            this.carriageWayStr=res.carriageWayStr
            this.loadingEffect=res.loadingEffect
            this.remarks=res.remarks
            //报价信息
            this.receivablePrice=res.receivablePrice?res.receivablePrice:"";
            this.receivablePriceUnitStr=res.receivablePriceUnitStr?res.receivablePriceUnitStr:"";
            this.receivableSummary=res.receivableSummary?res.receivableSummary:"";

          

            // 获取附件
            this.imageLists=[];
            if(res.attachmentList){
                res.attachmentList.forEach((item,index)=>{
                    item.index=index;
                    this.imageLists.push(item)
                })
            }



        },function(rej){
            // console.log("get Inquiry rejected")
            console.info(rej)
        })
        

        
        


    }
    
    winTheBid=function(){
        bootbox.confirm("确认已中标吗",(bootboxResult)=>{
            if(!bootboxResult){ //未确认时不跳转页面
                return;                  
            }
            dataService().Inquiry.editInquiry(this.id,"9").then(()=>{
                 window.location.href=window.location.origin+'/?#!/inquiry/inquiryManage';
            })


             
           
        })
    }

    loseTheBid=function(){
         bootbox.confirm("确认未中标吗",(bootboxResult)=>{
               if(!bootboxResult){ //未确认时不跳转页面
                return;                  
            }
             dataService().Inquiry.editInquiry(this.id,"10").then(()=>{
                 window.location.href=window.location.origin+'/?#!/inquiry/inquiryManage'
             })
              
        })
    }

    unKnow=function(){
        
        bootbox.confirm("确认中标待定吗",(bootboxResult)=>{
              if(!bootboxResult){ //未确认时不跳转页面
                return;                  
            }
             dataService().Inquiry.editInquiry(this.id,"11").then(()=>{
                 window.location.href=window.location.origin+'/?#!/inquiry/inquiryManage'
             })
              
        })
    }
    cancel=function(){
       
        // console.info(window.location)

       
         window.location.href=window.location.origin+'/?#!/inquiry/inquiryManage'
        
      
        
    }
    

}
